package org.example.StudentManagementSystem.common;

import lombok.Getter;
import lombok.Setter;
import io.swagger.v3.oas.annotations.media.Schema;

/**
 * 统一响应结果封装类
 */
@Setter
@Getter
@Schema(description = "统一响应结果")
public class Result {
    @Schema(description = "状态码 (200:成功, 其他:错误)", example = "200")
    private String code;

    @Schema(description = "提示信息", example = "操作成功")
    private String msg;

    @Schema(description = "返回数据")
    private Object data;

    public Result() {
    }

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Result success(Object data, String msg) {
        return new Result("200", msg, data);
    }

    public static Result success(String msg) {
        return new Result("200", msg, null);
    }

    public static Result error(String msg) {
        return new Result("500", msg, null);
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg);
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
